import { defineStore } from "pinia";
import { Size } from "@/plugins/element";
export const useAppStore = defineStore('app', () =>{
    // 状态
    const state = reactive({
      siberbar: {
        // siberbar 展开状态
        opened: false,
      },
      size: "default",
      language: 'zh-CN'
    })
    const sidebar = computed(() => state.siberbar)
    const size = computed(() => state.size);
    const language = computed(() => state.language);

    const setSize = (size: Size) => {
      state.size = size;
    };
    
    const setLanguage = (language: any) => {
      state.language = language;
    };
    // actions
    const toggleSidebar = () => {
      state.siberbar.opened = !state.siberbar.opened
    }
    // 需要导出响应式数据，persist 插件才会存储
    return {
      state,
      sidebar,
      toggleSidebar,
      setSize,
      size,
      setLanguage,
      language
    }
  },
  {
    persist: {
      storage: window.sessionStorage,
      paths: ["state.siderbar.opened", "state.size", "state.language"]
    }
  }
)